package com.wyl.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.wyl.model.Detail;
import com.wyl.model.Page;
import com.wyl.model.Simple;
import com.wyl.service.DetailService;
import com.wyl.service.SimpleService;

@RestController
public class ApiController {
	
	@Autowired
	SimpleService simpleService;
	
	@Autowired
	DetailService detailService;
	
	@RequestMapping("/news/api")
	public Page newsApi(@RequestParam("type")String type,@RequestParam("page")int page,@RequestParam("limit")int limit) {
		Page data = new Page();
		List<Simple> list = simpleService.selectByTypeAndPage(type, page, limit);
		data.setList(list);
		data.setSize(list.size());
		return data;
	}
	
	@RequestMapping("/detail/api")
	public Detail detailApi(@RequestParam("simpleId")int simpleId) {
		Detail detail = detailService.selectById(simpleId);
		if(detail==null) detail = new Detail();
		return detail;
	}
}
